<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function checked_exists($arr,$val){
    if(in_array($val,$arr,true)) return " checked";
    else return "";
}

function hash_func($str){
    return md5($str);
}

function replace_quotes($str){
    //$str = urldecode($str);
    //$str = html_entity_decode($str);
    //$str = stripslashes($str);
    //$str = htmlspecialchars($str);
    $str = str_replace(array("'","\"","`","/","\\"," "),"",$str);
    return $str;
}

function my_parse_url_params($str){
    $url = parse_url(replace_quotes($str));
    $path  = $url['path'];
    $query = empty ($url['query'])?"":$url['query'];
    
    $params = array();
    $tmp = split("&", $query);
    foreach ($tmp as $value) {
        $str2 = split("=", $value);
        $params[$str2['0']] = $str2['1'];
    }
    return $params;
}

function my_check_date($str){
    $formdate = strip_quotes($str);
    if(preg_match_all("/(\d{1,2})[.](\d{1,2})[.](\d{4})/", $formdate,$out,PREG_SET_ORDER)){
        return checkdate ( $out[0][2], $out[0][1], $out[0][3] );
    }else
        return false;
}
/**
 * @param type $str
 * @return int
 */
function my_digit_only($str){
    $res = preg_replace("/\D/", "", $str);
    return (int)$res;
}

function my_check_digit($digit){
    return preg_match("/^\d+$/", $digit)?true:false; //^\d{1,4}$
}
/**
 * Diplay array for html
 * @param array() $array
 * @return string 
 */
function my_print_r($array){
    return '<pre>'.print_r($array,true).'</pre><br>';
}

function my_var_dump($expression,$exit=true){
    echo "<pre>";
    var_dump($expression);
    echo "</pre>";
    if($exit) exit();
}


//joke :)
/*function get_h_banner($user){
    if($user == 'art'){
        if(rand(1,100)%2){
            echo '<br><center><a href="http://www.beeline.ru/"><img border="0" title="" src="/images/ml/h'.rand(1,10).'.gif"></a></center>';
        }else{
            echo '<br><center><nobr><a href="http://www.beeline.ru/"><img border="0" title="" src="/images/ml/hm'.rand(1,7).'.gif"></a> <a href="http://www.beeline.ru/"><img border="0" title="" src="/images/ml/hm'.rand(1,7).'.gif"></a></nobr></center>';
        }
    }
}
function get_v_banner($user){
    if($user == 'art'){
        $s = rand(1,10);
        echo '<a href="http://www.beeline.ru/"><img border="0" title="" src="/images/ml/v'.$s.'.gif"></a><br>';

    }
}*/
